local cars = {}

-- 处理客户端发送的 checkcar 事件
RegisterServerEvent("jobgarger:checkcar")
AddEventHandler("jobgarger:checkcar", function(vehicleInfo)
	local plate = vehicleInfo.plate
	local vehicle = vehicleInfo.model
	local coords = vehicleInfo.coords
	local livery = vehicleInfo.livery
	local extra1 = vehicleInfo.extra3
	local extra2 = vehicleInfo.extra4

	-- 检查车牌是否存在
	local carExists = false
	for i, car in ipairs(cars) do
		if car.plate == plate then
			carExists = true
			break
		end
	end

	if carExists then
		print("车牌已存在")
	else
		print("车牌不存在")

		-- 将新车辆信息添加到 cars 表格
		local carInfo = {
			model = vehicle,
			coords = coords,
			plate = plate,
			livery = livery,
			extra3 = extra1,
			extra4 = extra2,
		}
		table.insert(cars, carInfo)
		-- 触发客户端事件，向客户端出示该车辆
		TriggerClientEvent("jobgarger:givecar", source, vehicle, coords, plate, livery, extra1, extra2)
	end
end)
-- 处理删除车辆事件
RegisterServerEvent("jobgarger:deletecar")
AddEventHandler("jobgarger:deletecar", function(plate)
	print(plate)
	for i, car in ipairs(cars) do
		for i, car in ipairs(cars) do
			p1 = car.plate
			p2 = plate -- 添加空格
			if p1 == p2 then
				table.remove(cars, i)
			else
			end
		end
	end
end)
